package com.example.demo.page.demo

import com.example.demo.dao.UserDao
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber

//异步数据操作
class DemoRepository(private val userDao: UserDao) {

    suspend fun login(name: String, pwd: String): Boolean {
        var isLoginSuccess = false
        withContext(Dispatchers.IO) {
            val list = userDao.getAllUsers()
            Timber.d("userDao.getAllUsers()=$list")
            Timber.d("uname=$name|pwd=$pwd")
            if (list.isNotEmpty()) {
                isLoginSuccess = list.first().name == name && list.first().pwd == pwd
            }
        }
        return isLoginSuccess
    }
}